<?php 
@session_start();
$sess_id=$_SESSION['sess_id'];
$sess_user=$_SESSION['sess_user'];
$sess_status=$_SESSION['sess_status'];
$flag = $_SESSION['sess_flag'];
if ($sess_id<>session_id() || $sess_user=="" || $sess_status<>"active") {
		header( "Location: login.php");exit();
	}
include('config.inc.php');
include('runid.php');
$user_see = $_POST['user_see'];
$sql = "SELECT d.day_in,d.no,d.problem,d.day_process,d.day_complete,fa.fault_name,lo.site_name,st.status_id,st.status_detail,lo.location_id,
u1.name as unote,u1.unit_code as unote_unit,u1.pnthai as unote_pn, u1.tel as unote_tel,u1.fax as unote_fax,u1.office as unote_office,
u2.name as upro,u2.unit_code as upro_unit,u2.pnthai as upro_pn,u2.tel as upro_tel,u2.fax as upro_fax,u2.office as upro_office
FROM detail d
left join fault_type fa on d.fault_type = fa.id
left join location lo on d.location_id = lo.location_id
left join status_type st on d.status = st.status_id
left join users u1 on d.username_note = u1.username 
left join users u2 on d.username_process = u2.username 
where d.username_note = '$user_see' group by d.no";
$result = mysql_query($sql);
$num = mysql_num_rows($result);
?>
<table width='100%' border='1' cellspacing='0' cellpadding='3'>
	  <tr bgcolor="#535353">
		<td><font color="#FFFFFF"><strong><small>ลำดับ</small></strong></font></td>
		<td width="14%" ><font color="#FFFFFF"><small><strong>วันที่ทำการแจ้ง </strong></small></font></td>
		<td width="17%" bgcolor="#535353" ><font color="#FFFFFF"><strong><small>หมายเลขการแจ้ง</small></strong></font></td>
		<td width="12%" ><font color="#FFFFFF"><strong><small>ประเภทเหตุเสีย</small></strong></font></td>
		<td width="14%" ><font color="#FFFFFF"><strong><small>สถานที่</small></strong></font></td>
		<td width="20%" ><font color="#FFFFFF"><strong><small>เหตุเสีย</small></strong></font></td>
		<td width="13%" ><font color="#FFFFFF"><strong><small>สถานะ</small></strong></font></td>
	  	<td width="8%" ><font color="#FFFFFF"><strong><small>ผู้ดำเนินการ</small></strong></font></td>
  </tr>
<?php
if($result){
	$n = 1;
	while($arr=mysql_fetch_array($result)){
		if($n%2==0){
			$bgcolor = '#EBEBEB';
		}else{
			$bgcolor = '#FFFFFF';
		}
		echo "<tr bgcolor='$bgcolor'>";
		echo "<td align='center'><small>$n</small></td>";
		echo "<td><small>".thDate($arr[day_in])."&nbsp;</small></td>";
		echo "<td><small><a href='showfaultdetail.php?no=".$arr[no]."' style='text-decoration:underline;color:#000000;' target='_blank'>".$arr[no]."</a>&nbsp;</small></td>";
		echo "<td><small>".$arr[fault_name]."&nbsp;</small></td>";
		echo "<td><small>".$arr[location_id]."-<br>".$arr[site_name]."&nbsp;</small></td>";
		echo "<td><small>".$arr[problem]."&nbsp;</small></td>";
		echo "<td><small>".$arr[status_detail]."&nbsp;</small></td>";
		echo "<td><small>";
		if($arr[upro]==null){echo "ยังไม่มี";}else{ echo $arr[upro]; }
		echo "&nbsp;</small></td>";
		echo "</tr>";
		$n++;
	}
}
if($num == 0){
	echo "<tr><td colspan=8 align='center' style='padding:20px 0px 10px 0px;'><small><h2><font color='red'>คุณยังไ่ม่มีรายการให้ฐานข้อมูล</font></h2></small></td></tr>";
}
mysql_close($connect);
?>
</table>
